﻿CREATE PROCEDURE [sp_ssiscatalog].[execs]
		@execs_folder_name			sysname			=	NULL
,		@execs_project_name			sysname			=	NULL
,		@execs_package_name			sysname			=	NULL
,		@execs_executed_as_name		sysname			=	NULL
,		@execs_status_desc			NVARCHAR(MAX)	=	NULL
,		@execs_minimum_execution_id	BIGINT			=	NULL
,		@execs_maximum_execution_id	BIGINT			=	NULL
,		@show_docs					BIT				=	1
,		@show_docs_only				BIT				=	0
AS
BEGIN
		SET NOCOUNT ON;
		DECLARE	@vDocs	NVARCHAR(MAX)	=	N'Parameters:
@execs_folder_name			sysname			=	NULL		/*Filter list of executions by folder_name*/
@execs_project_name			sysname			=	NULL		/*Filter list of executions by project_name*/
@execs_package_name			sysname			=	NULL		/*Filter list of executions by package_name*/
@execs_executed_as_name		sysname			=	NULL		/*Filter list of executions by executed_as_name*/
@execs_status_desc			NVARCHAR(MAX)	=	NULL		/*Filter list of executions by status_desc (i.e. status description)*/
@execs_minimum_execution_id	BIGINT			=	NULL		/*Filter list of executions by getting all executions since this execution id*/
@execs_maximum_execution_id	BIGINT			=	NULL		/*Filter list of executions by getting all executions since up to this execution id*/
';
		EXEC	[sp_ssiscatalog].[show_docs]
					@docs			=	@vDocs
				,	@action			=	N'execs'
				,	@show_docs		=	@show_docs;
		IF (@show_docs_only = 1)
				RETURN;
		BEGIN TRY
				SELECT	e.[ResultSet],e.[folder_name],e.[project_name],e.[package_name],e.[executed_as_name],e.[status_desc],e.[start_time],e.[end_time],e.duration_in_seconds,e.[execution_id],e.relative_duration
				FROM	[sp_ssiscatalog].[executions](DEFAULT,@execs_folder_name,@execs_project_name,@execs_package_name,@execs_executed_as_name,@execs_status_desc,@execs_minimum_execution_id,@execs_maximum_execution_id) e
				ORDER	BY e.[execution_id] DESC;
				RAISERROR('%d executions returned',1,1,@@ROWCOUNT);
		END TRY
		BEGIN CATCH      
				THROW;
		END CATCH
END
	